﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MultipleQueue.Entities;
using MultipleQueue.Distributions;
using MultipleQueue.Simulation;
using System.Data;

namespace MultipleQueue
{
    public class SimulationManager
    {
        private float averageWaitingTime = 0;
        private DataTable averageServiceTime;
        private DataTable customersTable;
        private DataTable idleServerProbability;
        private float probabilityOfWait = 0;
        private List<Customer> completedCustomers;
        MultipleQueue.Simulation.Model model;
        private List<Model.CustomersQueue> queueGraph;
        /// <summary>
        /// List of servers
        /// </summary>
        private List<Entities.Server> servers;


        /// <summary>
        /// Gets the servers.
        /// </summary>
        public List<Entities.Server> Servers
        {
            get { return servers; }
        }

        public List<Customer> CompletedCustomers
        {
            get
            {
                return this.completedCustomers;
            }
        }

        public List<Model.CustomersQueue> QueueGraph
        {
            get
            {
                return this.queueGraph;
            }
        }

        public float ProbabilityOfWait
        {
            get
            {
                return this.probabilityOfWait;
            }
        }

        public DataTable IdleServerProbability
        {
            get
            {
                return this.idleServerProbability;
            }
        }

        public DataTable CustomersTable
        {
            get
            {
                return this.customersTable;
            }
        }

        public DataTable AverageServiceTime
        {
            get
            {
                return this.averageServiceTime;
            }
        }

        public float AverageWaitingTime
        {
            get
            {
                return this.averageWaitingTime;
            }
        }
        public MultipleQueue.Simulation.Model Model
        {
            get { return this.model; }
        }
        public void StartSimulation(int numberOfServers, Server[] servers, ServerSelection serverSelection, string stoppingConditionType, int stoppingConditionValue, IDistribution interarrivalDistributionType)
        {
            model = new Model(serverSelection, interarrivalDistributionType, servers.ToList<Server>(), stoppingConditionValue, stoppingConditionType);
            model.Run();
            model.CalculateSystemPerformance();
            this.probabilityOfWait = model.ProbabilityOfWait;
            this.customersTable = model.CustomerTable;
            this.averageServiceTime = model.AverageServiceTime;
            this.averageWaitingTime = model.AverageWaitingTime;
            this.idleServerProbability = model.IdleServerProbability;
            this.queueGraph = model.CustomersQueueGraph;
            this.completedCustomers = model.CompletedCustomers;
            this.servers = model.Servers;

            //throw new NotImplementedException(@"Implement StartSimulation in SimulationManager.cs");

            //get all inputs from the user
            //create the model
            //start running the simulation
        }
    }
}
